package com.example.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.DesensitizedUtil;
import com.example.demo.bean.UserBean;
import com.example.demo.bean.dto.UserLoginDTO;
import com.example.demo.dao.IUserLoginDao;
import com.example.demo.service.IUserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
 *
 *   @Author:max
 *   @Date: 2024/3/4-03-04-21:02
 *
 */
@Service
public class UserLoginServiceImpl implements IUserLoginService {

    @Autowired
    private IUserLoginDao iUserLoginDao;


    @Override
    public UserLoginDTO userLoginByPass(UserBean userBean) {
        //用户登录
        UserBean bean = iUserLoginDao.selectByNameAndPass(userBean);
        //如果为空证明没有查询到用户
        if(bean == null){
            return null;
        }
        UserLoginDTO userLoginDTO = new UserLoginDTO();
        //抹掉密码
        BeanUtil.copyProperties(bean,userLoginDTO);

        //信息脱敏
        userLoginDTO.setPhone(DesensitizedUtil.mobilePhone(userLoginDTO.getPhone()));
        userLoginDTO.setIdCard(DesensitizedUtil.idCardNum(userLoginDTO.getIdCard(),3,6));

        return userLoginDTO;
    }

}
